package leetcode_core.leetcode_4;

import java.util.Stack;

/**
 * 功能描述
 *
 * @author: 张庭杰
 * @date: 2022年10月21日 11:43
 */
public class StockSpanner {
    private Stack<Stock> stocks;
    public StockSpanner() {
        stocks = new Stack<>();
    }

    public int next(int price) {
        int day = 1;//包含自己的天数
        while (!stocks.isEmpty() && stocks.peek().price <= price){
            day += stocks.pop().day;
        }
        stocks.add(new Stock(price,day));
        return day;
    }

    class Stock{
        //定义数值对
        int price;
        int day;
        public Stock(int price, int day) {
            this.price = price;
            this.day = day;
        }
    }

}
